package com.atguigu.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/servletA")
public class ServletA extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 创建cookie
        Cookie cookie1 = new Cookie("cookie1", "value1");
        Cookie cookie2 = new Cookie("cookie2", "value2");

        // 设置了有效时间的cookie叫持久化cookie
        // 没有设置有效时间的cookie叫会话级cookie
        // 会话级cookie关闭浏览器后即不存在
        cookie1.setMaxAge(60);

        // 设置cookie的提交路径,就会在请求非路径资源的时候不提交cookie
        cookie1.setPath("/servletB");

        // cookie放入resp
        resp.addCookie(cookie1);
        resp.addCookie(cookie2);
    }
}
